< previous page page_334 next page >

Page 334
Note.gif
The Recordset created with this method is a very extensive object itself. You'll learn more about the Recordset object's properties and methods later in this chapter.

Using the Execute Method
You can use the Execute method on a database to perform SQL action queries. The Execute method updates the RecordsAffected property of the Database object with the total number of records found or updated by the SQL statement.
Note.gif
An action query is an SQL statement that performs an action on a database (add, edit, or delete records; create or remove data tables; and so on). Action SQL queries are covered in detail on Day 13, "Creating Databases with SQL."

Add a new command button to your project. Set its Name property to cmdExecute and its Caption property to Execute. Add the code in Listing 9.12 to the cmdExecute_Click event.
Type.gifListing 9.12. Coding the cmdExecute_Click event.
Private Sub cmdExecute_Click()
    '
    ' execute an SQL statement
    '
    Dim ws As Workspace
    Dim db As Database
    '
    Dim strDBName As String
    Dim strSQL As String
    Dim lngRecords As Long
    '
    ' init vars
    strDBName = App.Path & "\..\..\data\books5.mdb"
    strSQL = "DELETE FROM NewAuthors WHERE AUID<10"
    lngRecords = 0
    '
    ' open db in default ws
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase(strDBName)
    '
    ' perform SQL & get results
    db.Execute strSQL, dbFailOnError

 
< previous page page_334 next page >

If you like this book, buy it!